﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LongQuanWeb.App_Code;

namespace LongQuanWeb.Ventures
{
    public partial class Training : System.Web.UI.Page
    {
        public string year = "2013";//默认值为2013
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            //SubCategoryType 3 创业培训
            string strSql = "select distinct Top 4 YEAR(createtime) as year  from [Activity] Where SubCategoryType='3' order by YEAR(createtime) desc ";
            DataTable dt = DbHelperSQL.Query(strSql).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                year = dt.Rows[0]["year"].ToString().Trim();
            }
            this.rpt_active.DataSource = dt;
            this.rpt_active.DataBind();
        }

        private DataTable GetSource(string year)
        {
            string strSql = "select ActivityName,ActivityContent,AcitivityNum,substring(CONVERT(varchar, createtime, 120 ),6,2) as month,createtime From [Activity] where YEAR(createtime)='" + year + "' and SubCategoryType='3' order by month";
            DataTable dt = DbHelperSQL.Query(strSql).Tables[0];
            return dt;
        }

        //加载数据
        protected void rpt_active_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rpt = (Repeater)e.Item.FindControl("rpt_activecontent");
                DataRowView Drv = (DataRowView)e.Item.DataItem;
                string year = Drv["year"].ToString();
                rpt.DataSource = GetSource(year);
                rpt.DataBind();
            }
        }
    }
}
